using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Hanoi
{
    public class FormColumns : Hanoi.FormOptions
    {
        private PictureBox pbStart;
        private PictureBox pbEnd;
        private Label lblStartColumn;
        private Label lblEndColumn;
        private ComboBox cbStartColumn;
        private ComboBox cbEndColumn;
        private System.ComponentModel.IContainer components = null;

        private Form _callerForm;
        private Form _disksNumberForm;
        private Panel pnControls;
        private Hanoi.Logic.Profiles.CustomProfile _cp;

        public FormColumns(Form caller, Hanoi.Logic.Profiles.CustomProfile cp, Form diskNumberForm)
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();
            base.CenterPanel(this.pnControls);

            cbStartColumn.Focus();
            cbStartColumn.SelectedIndex = 0;
            _callerForm = caller;
            _disksNumberForm = diskNumberForm;
            _cp = cp;
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pbStart = new System.Windows.Forms.PictureBox();
            this.pbEnd = new System.Windows.Forms.PictureBox();
            this.lblStartColumn = new System.Windows.Forms.Label();
            this.lblEndColumn = new System.Windows.Forms.Label();
            this.cbStartColumn = new System.Windows.Forms.ComboBox();
            this.cbEndColumn = new System.Windows.Forms.ComboBox();
            this.pnControls = new System.Windows.Forms.Panel();
            // 
            // mnuPrevious
            // 
            this.mnuPrevious.Click += new System.EventHandler(this.mnuPrevious_Click);
            // 
            // mnuNext
            // 
            this.mnuNext.Click += new System.EventHandler(this.mnuNext_Click);
            // 
            // pnOptions
            // 
            this.pnOptions.Controls.Add(this.pnControls);
            // 
            // lblInfo
            // 
            this.lblInfo.Font = new System.Drawing.Font("Nina", 8F, System.Drawing.FontStyle.Regular);
            this.lblInfo.Text = "First, choose the first column (that in which you\'ll find the disks).\r\nThen, choo" +
                "se the columns you have to move them to.";
            // 
            // pbStart
            // 
            this.pbStart.Location = new System.Drawing.Point(0, 6);
            this.pbStart.Size = new System.Drawing.Size(64, 48);
            // 
            // pbEnd
            // 
            this.pbEnd.Location = new System.Drawing.Point(0, 60);
            this.pbEnd.Size = new System.Drawing.Size(64, 48);
            // 
            // lblStartColumn
            // 
            this.lblStartColumn.Font = new System.Drawing.Font("Nina", 10F, System.Drawing.FontStyle.Regular);
            this.lblStartColumn.Location = new System.Drawing.Point(70, 6);
            this.lblStartColumn.Size = new System.Drawing.Size(72, 22);
            this.lblStartColumn.Text = "Start Column";
            // 
            // lblEndColumn
            // 
            this.lblEndColumn.Font = new System.Drawing.Font("Nina", 10F, System.Drawing.FontStyle.Regular);
            this.lblEndColumn.Location = new System.Drawing.Point(70, 62);
            this.lblEndColumn.Size = new System.Drawing.Size(72, 22);
            this.lblEndColumn.Text = "End Column";
            // 
            // cbStartColumn
            // 
            this.cbStartColumn.DisplayMember = "1";
            this.cbStartColumn.Font = new System.Drawing.Font("Nina", 10F, System.Drawing.FontStyle.Regular);
            this.cbStartColumn.Items.Add("1");
            this.cbStartColumn.Items.Add("2");
            this.cbStartColumn.Items.Add("3");
            this.cbStartColumn.Location = new System.Drawing.Point(70, 29);
            this.cbStartColumn.Size = new System.Drawing.Size(72, 23);
            this.cbStartColumn.ValueMember = "1";
            this.cbStartColumn.SelectedIndexChanged += new System.EventHandler(this.cbStartColumn_SelectedIndexChanged);
            // 
            // cbEndColumn
            // 
            this.cbEndColumn.DisplayMember = "1";
            this.cbEndColumn.Font = new System.Drawing.Font("Nina", 10F, System.Drawing.FontStyle.Regular);
            this.cbEndColumn.Items.Add("1");
            this.cbEndColumn.Items.Add("2");
            this.cbEndColumn.Items.Add("3");
            this.cbEndColumn.Location = new System.Drawing.Point(70, 85);
            this.cbEndColumn.Size = new System.Drawing.Size(72, 23);
            this.cbEndColumn.ValueMember = "1";
            this.cbEndColumn.SelectedIndexChanged += new System.EventHandler(this.cbEndColumn_SelectedIndexChanged);
            // 
            // pnControls
            // 
            this.pnControls.Controls.Add(this.lblEndColumn);
            this.pnControls.Controls.Add(this.lblStartColumn);
            this.pnControls.Controls.Add(this.pbEnd);
            this.pnControls.Controls.Add(this.pbStart);
            this.pnControls.Controls.Add(this.cbEndColumn);
            this.pnControls.Controls.Add(this.cbStartColumn);
            this.pnControls.Location = new System.Drawing.Point(16, 7);
            this.pnControls.Size = new System.Drawing.Size(144, 113);
            // 
            // FormColumns
            // 
            this.ClientSize = new System.Drawing.Size(176, 180);
            this.Font = new System.Drawing.Font("Nina", 8F, System.Drawing.FontStyle.Regular);
            this.Text = "Columns";

        }
        #endregion

        #region My code
        Hanoi.Ui.ColumnsConfigUi ccui = null;
        Hanoi.Ui.ColumnsConfigUiConditioned ccuic = null;

        private void cbStartColumn_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = int.Parse(cbStartColumn.SelectedItem.ToString());
            if (ccui == null)
                ccui = new Hanoi.Ui.ColumnsConfigUi(pbStart.Width, pbStart.Height);
            ccui.Selected = index;
            pbStart.Image = ccui.GetImage();

            cbEndColumn.Items.Clear();
            for (int i = 1; i < 4; i++)
                if (i != index)
                    cbEndColumn.Items.Add(i.ToString());
            if (ccuic == null)
                ccuic = new Hanoi.Ui.ColumnsConfigUiConditioned(pbEnd.Width, pbEnd.Height, int.Parse(cbStartColumn.SelectedItem.ToString()));
            ccuic.NotDispensable = index - 1;
            cbEndColumn.SelectedIndex = 1;
        }

        #endregion

        private void cbEndColumn_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = int.Parse(cbEndColumn.SelectedItem.ToString());
            if (ccuic == null)
                ccuic = new Hanoi.Ui.ColumnsConfigUiConditioned(pbEnd.Width, pbEnd.Height, int.Parse(cbStartColumn.SelectedItem.ToString()));
            ccuic.Selected = index;
            pbEnd.Image = ccuic.GetImage();

        }

        private void mnuPrevious_Click(object sender, EventArgs e)
        {
            _callerForm.Show();
            _callerForm.Visible = true;
            _callerForm.BringToFront();

            _disksNumberForm.Dispose();
            this.Dispose();
        }

        private void mnuNext_Click(object sender, EventArgs e)
        {
            int start, end;
            start = int.Parse(cbStartColumn.SelectedItem.ToString());
            end = int.Parse(cbEndColumn.SelectedItem.ToString());

            _cp.Start = start - 1;
            _cp.End = end - 1;

            (new FormLevel(_callerForm, _cp, _disksNumberForm, this)).Show();
            this.Hide();
        }
    }
}
